// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.iso.objects;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import zombie.core.Rand;
import zombie.core.Translator;
import zombie.core.logger.ExceptionLogger;
import zombie.core.network.ByteBufferWriter;
import zombie.core.properties.PropertyContainer;
import zombie.core.raknet.UdpConnection;
import zombie.inventory.InventoryItem;
import zombie.inventory.ItemContainer;
import zombie.inventory.types.Food;
import zombie.iso.IsoCell;
import zombie.iso.IsoChunk;
import zombie.iso.IsoGridSquare;
import zombie.iso.IsoObject;
import zombie.iso.IsoUtils;
import zombie.iso.IsoWorld;
import zombie.iso.SpriteDetails.IsoFlagType;
import zombie.iso.sprite.IsoSpriteManager;
import zombie.network.GameClient;
import zombie.network.GameServer;
import zombie.network.PacketTypes;
import zombie.network.ServerMap;

public class IsoGenerator extends IsoObject {
    public float fuel = 0.0F;
    public boolean activated = false;
    public int condition = 0;
    private int lastHour = -1;
    public boolean connected = false;
    private int numberOfElectricalItems = 0;
    private boolean updateSurrounding = false;
    private final HashMap<String, String> itemsPowered = new HashMap();
    private float totalPowerUsing = 0.0F;
    private static final ArrayList<IsoGenerator> AllGenerators = new ArrayList();
    private static final int GENERATOR_RADIUS = 20;

    public IsoGenerator(IsoCell cell) {
        super(cell);
    }

    public IsoGenerator(InventoryItem item, IsoCell cell, IsoGridSquare sq) {
        super(cell, sq, IsoSpriteManager.instance.getSprite("appliances_misc_01_0"));
        if (item != null) {
            this.setInfoFromItem(item);
        }

        this.sprite = IsoSpriteManager.instance.getSprite("appliances_misc_01_0");
        this.square = sq;
        sq.AddSpecialObject(this);
        if (GameClient.bClient) {
            this.transmitCompleteItemToServer();
        }
    }

    public IsoGenerator(InventoryItem item, IsoCell cell, IsoGridSquare sq, boolean remote) {
        super(cell, sq, IsoSpriteManager.instance.getSprite("appliances_misc_01_0"));
        if (item != null) {
            this.setInfoFromItem(item);
        }

        this.sprite = IsoSpriteManager.instance.getSprite("appliances_misc_01_0");
        this.square = sq;
        sq.AddSpecialObject(this);
        if (GameClient.bClient && !remote) {
            this.transmitCompleteItemToServer();
        }
    }

    public void setInfoFromItem(InventoryItem item) {
        this.condition = item.getCondition();
        if (item.getModData().rawget("fuel") instanceof Double) {
            this.fuel = ((Double)item.getModData().rawget("fuel")).floatValue();
        }
    }

    @Override
    public void update() {
        if (this.updateSurrounding && this.getSquare() != null) {
            this.setSurroundingElectricity();
            this.updateSurrounding = false;
        }

        if (this.isActivated()) {
            if (!GameServer.bServer && (this.emitter == null || !this.emitter.isPlaying("GeneratorLoop"))) {
                if (this.emitter == null) {
                    this.emitter = IsoWorld.instance.getFreeEmitter(this.getX() + 0.5F, this.getY() + 0.5F, (float)((int)this.getZ()));
                    IsoWorld.instance.takeOwnershipOfEmitter(this.emitter);
                }

                this.emitter.playSoundLoopedImpl("GeneratorLoop");
            }

            if (GameClient.bClient) {
                this.emitter.tick();
                return;
            }

            zombie.WorldSoundManager.instance.addSoundRepeating(this, (int)this.getX(), (int)this.getY(), (int)this.getZ(), 20, 1, false);
            if ((int)zombie.GameTime.getInstance().getWorldAgeHours() != this.lastHour) {
                if (!this.getSquare().getProperties().Is(IsoFlagType.exterior) && this.getSquare().getBuilding() != null) {
                    this.getSquare().getBuilding().setToxic(false);
                    this.getSquare().getBuilding().setToxic(this.isActivated());
                }

                int int0 = (int)zombie.GameTime.getInstance().getWorldAgeHours() - this.lastHour;
                float float0 = 0.0F;
                int int1 = 0;

                for (int int2 = 0; int2 < int0; int2++) {
                    float float1 = this.totalPowerUsing;
                    float1 = (float)((double)float1 * zombie.SandboxOptions.instance.GeneratorFuelConsumption.getValue());
                    float0 += float1;
                    if (Rand.Next(30) == 0) {
                        int1 += Rand.Next(2) + 1;
                    }

                    if (this.fuel - float0 <= 0.0F || this.condition - int1 <= 0) {
                        break;
                    }
                }

                this.fuel -= float0;
                if (this.fuel <= 0.0F) {
                    this.setActivated(false);
                    this.fuel = 0.0F;
                }

                this.condition -= int1;
                if (this.condition <= 0) {
                    this.setActivated(false);
                    this.condition = 0;
                }

                if (this.condition <= 20) {
                    if (Rand.Next(10) == 0) {
                        IsoFireManager.StartFire(this.getCell(), this.square, true, 1000);
                        this.condition = 0;
                        this.setActivated(false);
                    } else if (Rand.Next(20) == 0) {
                        this.square.explode();
                        this.condition = 0;
                        this.setActivated(false);
                    }
                }

                this.lastHour = (int)zombie.GameTime.getInstance().getWorldAgeHours();
                if (GameServer.bServer) {
                    this.syncIsoObject(false, (byte)0, null, null);
                }
            }
        }

        if (this.emitter != null) {
            this.emitter.tick();
        }
    }

    public void setSurroundingElectricity() {
        this.itemsPowered.clear();
        this.totalPowerUsing = 0.02F;
        this.numberOfElectricalItems = 1;
        if (this.square != null && this.square.chunk != null) {
            int int0 = this.square.chunk.wx;
            int int1 = this.square.chunk.wy;

            for (int int2 = -2; int2 <= 2; int2++) {
                for (int int3 = -2; int3 <= 2; int3++) {
                    IsoChunk isoChunk = GameServer.bServer
                        ? ServerMap.instance.getChunk(int0 + int3, int1 + int2)
                        : IsoWorld.instance.CurrentCell.getChunk(int0 + int3, int1 + int2);
                    if (isoChunk != null && this.touchesChunk(isoChunk)) {
                        if (this.isActivated()) {
                            isoChunk.addGeneratorPos(this.square.x, this.square.y, this.square.z);
                        } else {
                            isoChunk.removeGeneratorPos(this.square.x, this.square.y, this.square.z);
                        }
                    }
                }
            }

            boolean boolean0 = zombie.SandboxOptions.getInstance().AllowExteriorGenerator.getValue();
            int int4 = this.square.getX() - 20;
            int int5 = this.square.getX() + 20;
            int int6 = this.square.getY() - 20;
            int int7 = this.square.getY() + 20;
            int int8 = Math.max(0, this.getSquare().getZ() - 3);
            int int9 = Math.min(8, this.getSquare().getZ() + 3);

            for (int int10 = int8; int10 < int9; int10++) {
                for (int int11 = int4; int11 <= int5; int11++) {
                    for (int int12 = int6; int12 <= int7; int12++) {
                        if (!(
                            IsoUtils.DistanceToSquared(
                                    (float)int11 + 0.5F, (float)int12 + 0.5F, (float)this.getSquare().getX() + 0.5F, (float)this.getSquare().getY() + 0.5F
                                )
                                > 400.0F
                        )) {
                            IsoGridSquare isoGridSquare = this.getCell().getGridSquare(int11, int12, int10);
                            if (isoGridSquare != null) {
                                boolean boolean1 = this.isActivated();
                                if (!boolean0 && isoGridSquare.Is(IsoFlagType.exterior)) {
                                    boolean1 = false;
                                }

                                isoGridSquare.setHaveElectricity(boolean1);

                                for (int int13 = 0; int13 < isoGridSquare.getObjects().size(); int13++) {
                                    IsoObject isoObject = isoGridSquare.getObjects().get(int13);
                                    if (isoObject != null && !(isoObject instanceof IsoWorldInventoryObject)) {
                                        if (isoObject instanceof IsoClothingDryer && ((IsoClothingDryer)isoObject).isActivated()) {
                                            this.addPoweredItem(isoObject, 0.09F);
                                        }

                                        if (isoObject instanceof IsoClothingWasher && ((IsoClothingWasher)isoObject).isActivated()) {
                                            this.addPoweredItem(isoObject, 0.09F);
                                        }

                                        if (isoObject instanceof IsoCombinationWasherDryer && ((IsoCombinationWasherDryer)isoObject).isActivated()) {
                                            this.addPoweredItem(isoObject, 0.09F);
                                        }

                                        if (isoObject instanceof IsoStackedWasherDryer) {
                                            IsoStackedWasherDryer isoStackedWasherDryer = (IsoStackedWasherDryer)isoObject;
                                            float _float = 0.0F;
                                            if (isoStackedWasherDryer.isDryerActivated()) {
                                                _float += 0.9F;
                                            }

                                            if (isoStackedWasherDryer.isWasherActivated()) {
                                                _float += 0.9F;
                                            }

                                            if (_float > 0.0F) {
                                                this.addPoweredItem(isoObject, _float);
                                            }
                                        }

                                        if (isoObject instanceof IsoTelevision && ((IsoTelevision)isoObject).getDeviceData().getIsTurnedOn()) {
                                            this.addPoweredItem(isoObject, 0.03F);
                                        }

                                        if (isoObject instanceof IsoRadio
                                            && ((IsoRadio)isoObject).getDeviceData().getIsTurnedOn()
                                            && !((IsoRadio)isoObject).getDeviceData().getIsBatteryPowered()) {
                                            this.addPoweredItem(isoObject, 0.01F);
                                        }

                                        if (isoObject instanceof IsoStove && ((IsoStove)isoObject).Activated()) {
                                            this.addPoweredItem(isoObject, 0.09F);
                                        }

                                        boolean boolean2 = isoObject.getContainerByType("fridge") != null;
                                        boolean boolean3 = isoObject.getContainerByType("freezer") != null;
                                        if (boolean2 && boolean3) {
                                            this.addPoweredItem(isoObject, 0.13F);
                                        } else if (boolean2 || boolean3) {
                                            this.addPoweredItem(isoObject, 0.08F);
                                        }

                                        if (isoObject instanceof IsoLightSwitch && ((IsoLightSwitch)isoObject).Activated) {
                                            this.addPoweredItem(isoObject, 0.002F);
                                        }

                                        isoObject.checkHaveElectricity();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    private void addPoweredItem(IsoObject isoObject, float _float) {
        String string0 = Translator.getText("IGUI_VehiclePartCatOther");
        PropertyContainer propertyContainer = isoObject.getProperties();
        if (propertyContainer != null && propertyContainer.Is("CustomName")) {
            String string1 = "Moveable Object";
            if (propertyContainer.Is("CustomName")) {
                if (propertyContainer.Is("GroupName")) {
                    string1 = propertyContainer.Val("GroupName") + " " + propertyContainer.Val("CustomName");
                } else {
                    string1 = propertyContainer.Val("CustomName");
                }
            }

            string0 = Translator.getMoveableDisplayName(string1);
        }

        if (isoObject instanceof IsoLightSwitch) {
            string0 = Translator.getText("IGUI_Lights");
        }

        this.totalPowerUsing -= _float;
        int _int = 1;

        for (String string2 : this.itemsPowered.keySet()) {
            if (string2.startsWith(string0)) {
                _int = Integer.parseInt(string2.replaceAll("[\\D]", ""));
                _int++;
                this.itemsPowered.remove(string2);
                break;
            }
        }

        this.itemsPowered.put(string0 + " x" + _int, String.format(" (%.2f L/h)", _float * (float)_int));
        if (_int == 1) {
            this.totalPowerUsing += _float * (float)(_int + 1);
        } else {
            this.totalPowerUsing += _float * (float)_int;
        }
    }

    private void updateFridgeFreezerItems(IsoObject isoObject) {
        for (int int0 = 0; int0 < isoObject.getContainerCount(); int0++) {
            ItemContainer itemContainer = isoObject.getContainerByIndex(int0);
            if ("fridge".equals(itemContainer.getType()) || "freezer".equals(itemContainer.getType())) {
                ArrayList arrayList = itemContainer.getItems();

                for (int int1 = 0; int1 < arrayList.size(); int1++) {
                    InventoryItem inventoryItem = (InventoryItem)arrayList.get(int1);
                    if (inventoryItem instanceof Food) {
                        inventoryItem.updateAge();
                    }
                }
            }
        }
    }

    private void updateFridgeFreezerItems(IsoGridSquare isoGridSquare) {
        int int0 = isoGridSquare.getObjects().size();
        IsoObject[] isoObject0 = isoGridSquare.getObjects().getElements();

        for (int int1 = 0; int1 < int0; int1++) {
            IsoObject isoObject1 = isoObject0[int1];
            this.updateFridgeFreezerItems(isoObject1);
        }
    }

    private void updateFridgeFreezerItems() {
        if (this.square != null) {
            int int0 = this.square.getX() - 20;
            int int1 = this.square.getX() + 20;
            int int2 = this.square.getY() - 20;
            int int3 = this.square.getY() + 20;
            int int4 = Math.max(0, this.square.getZ() - 3);
            int int5 = Math.min(8, this.square.getZ() + 3);

            for (int int6 = int4; int6 < int5; int6++) {
                for (int int7 = int0; int7 <= int1; int7++) {
                    for (int int8 = int2; int8 <= int3; int8++) {
                        if (IsoUtils.DistanceToSquared((float)int7, (float)int8, (float)this.square.x, (float)this.square.y) <= 400.0F) {
                            IsoGridSquare isoGridSquare = this.getCell().getGridSquare(int7, int8, int6);
                            if (isoGridSquare != null) {
                                this.updateFridgeFreezerItems(isoGridSquare);
                            }
                        }
                    }
                }
            }
        }
    }

    @Override
    public void load(ByteBuffer input, int WorldVersion, boolean IS_DEBUG_SAVE) throws IOException {
        super.load(input, WorldVersion, IS_DEBUG_SAVE);
        this.connected = input.get() == 1;
        this.activated = input.get() == 1;
        if (WorldVersion < 138) {
            this.fuel = (float)input.getInt();
        } else {
            this.fuel = input.getFloat();
        }

        this.condition = input.getInt();
        this.lastHour = input.getInt();
        this.numberOfElectricalItems = input.getInt();
        this.updateSurrounding = true;
    }

    @Override
    public void save(ByteBuffer output, boolean IS_DEBUG_SAVE) throws IOException {
        super.save(output, IS_DEBUG_SAVE);
        output.put((byte)(this.isConnected() ? 1 : 0));
        output.put((byte)(this.isActivated() ? 1 : 0));
        output.putFloat(this.getFuel());
        output.putInt(this.getCondition());
        output.putInt(this.lastHour);
        output.putInt(this.numberOfElectricalItems);
    }

    public void remove() {
        if (this.getSquare() != null) {
            this.getSquare().transmitRemoveItemFromSquare(this);
        }
    }

    @Override
    public void addToWorld() {
        this.getCell().addToProcessIsoObject(this);
        if (!AllGenerators.contains(this)) {
            AllGenerators.add(this);
        }

        if (GameClient.bClient) {
            GameClient.instance.objectSyncReq.putRequest(this.square, this);
        }
    }

    @Override
    public void removeFromWorld() {
        AllGenerators.remove(this);
        if (this.emitter != null) {
            this.emitter.stopAll();
            IsoWorld.instance.returnOwnershipOfEmitter(this.emitter);
            this.emitter = null;
        }

        super.removeFromWorld();
    }

    @Override
    public String getObjectName() {
        return "IsoGenerator";
    }

    public float getFuel() {
        return this.fuel;
    }

    public void setFuel(float _fuel) {
        this.fuel = _fuel;
        if (this.fuel > 100.0F) {
            this.fuel = 100.0F;
        }

        if (this.fuel < 0.0F) {
            this.fuel = 0.0F;
        }

        if (GameServer.bServer) {
            this.syncIsoObject(false, (byte)0, null, null);
        }

        if (GameClient.bClient) {
            this.syncIsoObject(false, (byte)0, null, null);
        }
    }

    public boolean isActivated() {
        return this.activated;
    }

    public void setActivated(boolean _activated) {
        if (_activated != this.activated) {
            if (!this.getSquare().getProperties().Is(IsoFlagType.exterior) && this.getSquare().getBuilding() != null) {
                this.getSquare().getBuilding().setToxic(false);
                this.getSquare().getBuilding().setToxic(_activated);
            }

            if (!GameServer.bServer && this.emitter == null) {
                this.emitter = IsoWorld.instance.getFreeEmitter(this.getX() + 0.5F, this.getY() + 0.5F, this.getZ());
                IsoWorld.instance.takeOwnershipOfEmitter(this.emitter);
            }

            if (_activated) {
                this.lastHour = (int)zombie.GameTime.getInstance().getWorldAgeHours();
                if (this.emitter != null) {
                    this.emitter.playSound("GeneratorStarting");
                }
            } else if (this.emitter != null) {
                if (!this.emitter.isEmpty()) {
                    this.emitter.stopAll();
                }

                this.emitter.playSound("GeneratorStopping");
            }

            try {
                this.updateFridgeFreezerItems();
            } catch (Throwable throwable) {
                ExceptionLogger.logException(throwable);
            }

            this.activated = _activated;
            this.setSurroundingElectricity();
            if (GameClient.bClient) {
                this.syncIsoObject(false, (byte)0, null, null);
            }

            if (GameServer.bServer) {
                this.syncIsoObject(false, (byte)0, null, null);
            }
        }
    }

    public void failToStart() {
        if (!GameServer.bServer) {
            if (this.emitter == null) {
                this.emitter = IsoWorld.instance.getFreeEmitter(this.getX() + 0.5F, this.getY() + 0.5F, this.getZ());
                IsoWorld.instance.takeOwnershipOfEmitter(this.emitter);
            }

            this.emitter.playSound("GeneratorFailedToStart");
        }
    }

    public int getCondition() {
        return this.condition;
    }

    public void setCondition(int _condition) {
        this.condition = _condition;
        if (this.condition > 100) {
            this.condition = 100;
        }

        if (this.condition < 0) {
            this.condition = 0;
        }

        if (GameServer.bServer) {
            this.syncIsoObject(false, (byte)0, null, null);
        }

        if (GameClient.bClient) {
            this.syncIsoObject(false, (byte)0, null, null);
        }
    }

    public boolean isConnected() {
        return this.connected;
    }

    public void setConnected(boolean _connected) {
        this.connected = _connected;
        if (GameClient.bClient) {
            this.syncIsoObject(false, (byte)0, null, null);
        }
    }

    @Override
    public void syncIsoObjectSend(ByteBufferWriter b) {
        byte _byte = (byte)this.getObjectIndex();
        b.putInt(this.square.getX());
        b.putInt(this.square.getY());
        b.putInt(this.square.getZ());
        b.putByte(_byte);
        b.putByte((byte)1);
        b.putByte((byte)0);
        b.putFloat(this.fuel);
        b.putInt(this.condition);
        b.putByte((byte)(this.activated ? 1 : 0));
        b.putByte((byte)(this.connected ? 1 : 0));
    }

    @Override
    public void syncIsoObject(boolean bRemote, byte val, UdpConnection source, ByteBuffer bb) {
        if (this.square == null) {
            System.out.println("ERROR: " + this.getClass().getSimpleName() + " square is null");
        } else if (this.getObjectIndex() == -1) {
            System.out
                .println(
                    "ERROR: "
                        + this.getClass().getSimpleName()
                        + " not found on square "
                        + this.square.getX()
                        + ","
                        + this.square.getY()
                        + ","
                        + this.square.getZ()
                );
        } else {
            if (GameClient.bClient && !bRemote) {
                ByteBufferWriter byteBufferWriter0 = GameClient.connection.startPacket();
                PacketTypes.PacketType.SyncIsoObject.doPacket(byteBufferWriter0);
                this.syncIsoObjectSend(byteBufferWriter0);
                PacketTypes.PacketType.SyncIsoObject.send(GameClient.connection);
            } else if (GameServer.bServer && !bRemote) {
                for (UdpConnection udpConnection0 : GameServer.udpEngine.connections) {
                    ByteBufferWriter byteBufferWriter1 = udpConnection0.startPacket();
                    PacketTypes.PacketType.SyncIsoObject.doPacket(byteBufferWriter1);
                    this.syncIsoObjectSend(byteBufferWriter1);
                    PacketTypes.PacketType.SyncIsoObject.send(udpConnection0);
                }
            } else if (bRemote) {
                float _float = bb.getFloat();
                int _int = bb.getInt();
                boolean boolean0 = bb.get() == 1;
                boolean boolean1 = bb.get() == 1;
                this.sync(_float, _int, boolean1, boolean0);
                if (GameServer.bServer) {
                    for (UdpConnection udpConnection1 : GameServer.udpEngine.connections) {
                        if (source != null && udpConnection1.getConnectedGUID() != source.getConnectedGUID()) {
                            ByteBufferWriter byteBufferWriter2 = udpConnection1.startPacket();
                            PacketTypes.PacketType.SyncIsoObject.doPacket(byteBufferWriter2);
                            this.syncIsoObjectSend(byteBufferWriter2);
                            PacketTypes.PacketType.SyncIsoObject.send(udpConnection1);
                        }
                    }
                }
            }
        }
    }

    public void sync(float _fuel, int _condition, boolean _connected, boolean _activated) {
        this.fuel = _fuel;
        this.condition = _condition;
        this.connected = _connected;
        if (this.activated != _activated) {
            try {
                this.updateFridgeFreezerItems();
            } catch (Throwable throwable) {
                ExceptionLogger.logException(throwable);
            }

            this.activated = _activated;
            if (_activated) {
                this.lastHour = (int)zombie.GameTime.getInstance().getWorldAgeHours();
            } else if (this.emitter != null) {
                this.emitter.stopAll();
            }

            this.setSurroundingElectricity();
        }
    }

    private boolean touchesChunk(IsoChunk isoChunk) {
        IsoGridSquare isoGridSquare = this.getSquare();

        assert isoGridSquare != null;

        if (isoGridSquare == null) {
            return false;
        } else {
            int int0 = isoChunk.wx * 10;
            int int1 = isoChunk.wy * 10;
            int int2 = int0 + 10 - 1;
            int int3 = int1 + 10 - 1;
            if (isoGridSquare.x - 20 > int2) {
                return false;
            } else if (isoGridSquare.x + 20 < int0) {
                return false;
            } else {
                return isoGridSquare.y - 20 > int3 ? false : isoGridSquare.y + 20 >= int1;
            }
        }
    }

    public static void chunkLoaded(IsoChunk chunk) {
        chunk.checkForMissingGenerators();

        for (int int0 = -2; int0 <= 2; int0++) {
            for (int int1 = -2; int1 <= 2; int1++) {
                if (int1 != 0 || int0 != 0) {
                    IsoChunk isoChunk = GameServer.bServer
                        ? ServerMap.instance.getChunk(chunk.wx + int1, chunk.wy + int0)
                        : IsoWorld.instance.CurrentCell.getChunk(chunk.wx + int1, chunk.wy + int0);
                    if (isoChunk != null) {
                        isoChunk.checkForMissingGenerators();
                    }
                }
            }
        }

        for (int int2 = 0; int2 < AllGenerators.size(); int2++) {
            IsoGenerator isoGenerator = (IsoGenerator)AllGenerators.get(int2);
            if (!isoGenerator.updateSurrounding && isoGenerator.touchesChunk(chunk)) {
                isoGenerator.updateSurrounding = true;
            }
        }
    }

    public static void updateSurroundingNow() {
        for (int _int = 0; _int < AllGenerators.size(); _int++) {
            IsoGenerator isoGenerator = (IsoGenerator)AllGenerators.get(_int);
            if (isoGenerator.updateSurrounding && isoGenerator.getSquare() != null) {
                isoGenerator.updateSurrounding = false;
                isoGenerator.setSurroundingElectricity();
            }
        }
    }

    public static void updateGenerator(IsoGridSquare sq) {
        if (sq != null) {
            for (int _int = 0; _int < AllGenerators.size(); _int++) {
                IsoGenerator isoGenerator = (IsoGenerator)AllGenerators.get(_int);
                if (isoGenerator.getSquare() != null) {
                    float _float = IsoUtils.DistanceToSquared(
                        (float)sq.x + 0.5F, (float)sq.y + 0.5F, (float)isoGenerator.getSquare().getX() + 0.5F, (float)isoGenerator.getSquare().getY() + 0.5F
                    );
                    if (_float <= 400.0F) {
                        isoGenerator.updateSurrounding = true;
                    }
                }
            }
        }
    }

    public static void Reset() {
        assert AllGenerators.isEmpty();

        AllGenerators.clear();
    }

    public static boolean isPoweringSquare(int generatorX, int generatorY, int generatorZ, int x, int y, int z) {
        int int0 = Math.max(0, generatorZ - 3);
        int int1 = Math.min(8, generatorZ + 3);
        return z >= int0 && z < int1
            ? IsoUtils.DistanceToSquared((float)generatorX + 0.5F, (float)generatorY + 0.5F, (float)x + 0.5F, (float)y + 0.5F) <= 400.0F
            : false;
    }

    public ArrayList<String> getItemsPowered() {
        ArrayList arrayList = new ArrayList();

        for (String string : this.itemsPowered.keySet()) {
            arrayList.add(string + (String)this.itemsPowered.get(string));
        }

        arrayList.sort(String::compareToIgnoreCase);
        return arrayList;
    }

    public float getTotalPowerUsing() {
        return this.totalPowerUsing;
    }

    public void setTotalPowerUsing(float _totalPowerUsing) {
        this.totalPowerUsing = _totalPowerUsing;
    }
}
